package com.china08.yxyapi.api.manage.par.homework.workreport;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskReportRepository;

/**
 * 家长 查询班级作业未读数
 * 
 * @author lys
 * 
 */
@CrossOrigin
@RestController
public class HomReadCountController extends YxyApiBaseController {

    @Autowired
    private HomeworkTaskReportRepository homeworkTaskReportRepository;

    @RequestMapping(value = "/api_yw/manage/par/mystudy/workreport/homReadCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel,
            RespModel respModel) {
        Date currentDate = new Date();
        List<String> childIds = new ArrayList<String>();
        if (reqModel.childIds != null) {
            childIds = reqModel.childIds;
        }
        Integer count = homeworkTaskReportRepository
                .countByStatusOfFinishedAndPredictDateGreaterThanEqualAndPublishDateLessThanEqualAndStudentIdIn(0,
                        currentDate, currentDate, childIds);
        respModel = new RespModel();
        respModel.setCount(count);
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {

        private int count;

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }
    }

    protected static class ReqModel extends YxyApiPageReqModel {
        public List<String> childIds;
    }
}